//
//  NumberDNADetailVC.m
//  DaleTou
//
//  Created by anyfish010 on 2018/5/27.
//  Copyright © 2018年 geren. All rights reserved.
//

#import "NumberDNADetailVC.h"
#import "ZXTableView.h"
#import "XGConfig.h"
#import "DNADetailCell.h"
#import "Appearance.h"

@interface NumberDNADetailVC ()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic,strong)ZXTableView *mainTable;

@end

@implementation NumberDNADetailVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self setNavConfigStartColor:@"#F57321" endColor:@"#F57321"];
    [self ApptitileView:@"号码DNA"];
    self.view.backgroundColor = UIColorFromRGB(0xf5f5f5);
    

    _mainTable = [[ZXTableView alloc]initWithFrame:CGRectMake(0, NAV_HEIGHT, ScreenWidth, ScreenHeight -NAV_HEIGHT) style:UITableViewStyleGrouped];

    _mainTable.delegate = self;
    _mainTable.dataSource = self;
    [self.view addSubview:self.mainTable];
    
    if (@available(iOS 11.0, *)) {
        self.mainTable.contentInsetAdjustmentBehavior = UIApplicationBackgroundFetchIntervalNever;
    }else {
        self.automaticallyAdjustsScrollViewInsets = NO;
    }
    
    UIView *headView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 90)];
    _mainTable.tableHeaderView = headView;
    headView.backgroundColor = [UIColor whiteColor];
    
    CGFloat paddingX = 20;
    CGFloat padding = 10;
    CGFloat width = (ScreenWidth - paddingX * 2 - padding * 6)/7;
    CGFloat height = width;
    CGFloat paddingY = (headView.frame.size.height - height)/2;
    for (int i = 0 ; i < _mArrNumbers.count; i ++) {
        UIButton *btn = [[UIButton alloc]initWithFrame:CGRectMake(paddingX + (width + padding) * i, paddingY, width, height)];
        [headView addSubview:btn];
        [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [btn setTitle:_mArrNumbers[i] forState:UIControlStateNormal];
        if(i < 5){
            btn.backgroundColor = UIColorFromRGB(0xf04100);
        }else{
            btn.backgroundColor = UIColorFromRGB(0x0070d6);
        }
        btn.layer.cornerRadius = height/2;
        btn.layer.masksToBounds = YES;
    }
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    DNADetailCell *cell = [[NSBundle mainBundle]loadNibNamed:@"DNADetailCell" owner:nil options:nil].firstObject;
    if(indexPath.section == 0){
        cell.labTitle.text = @"号码历史中奖情况";
        
        NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:@"此号码在最近的1683次历史开奖中,共中过94次,中得715元，击败了88.1%的号码。"];
        NSString *string1 = @"此号码在最近的1683次历史开奖中,共中过94次,中得715元，击败了88.1%的号码。";
        NSRange range1 = [string1 rangeOfString:@"1683"];
        NSRange range2 = [string1 rangeOfString:@"94"];
        NSRange range3 = [string1 rangeOfString:@"715"];
        NSRange range4 = [string1 rangeOfString:@"88.1%"];

        [string addAttribute:NSForegroundColorAttributeName value:UIColorFromRGB(0xf04100) range:range1]; //设置字体颜色
        [string addAttribute:NSForegroundColorAttributeName value:UIColorFromRGB(0xf04100) range:range2]; //设置字体颜色
        [string addAttribute:NSForegroundColorAttributeName value:UIColorFromRGB(0xf04100) range:range3]; //设置字体颜色
        [string addAttribute:NSForegroundColorAttributeName value:UIColorFromRGB(0xf04100) range:range4]; //设置字体颜色
        cell.labcontent.attributedText = string;
        cell.imgV.image = [UIImage imageNamed:@"Slice"];
        
    }else{
        cell.labTitle.text = @"号码遗漏及连出情况";
        cell.labcontent.text = @"各个号码的历史遗漏和连出情况，以及当时遗漏和连出情况对比。";
        cell.imgV.image = [UIImage imageNamed:@"Slice2"];

    }
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 330;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 20;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0.1;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
